Ext.define('AmpleHarvest.views.article.cAreaCenter',
{
	extend				: 'Ext.panel.Panel',
	alias				: 'widget.ampleharvest-views-article-careacenter',
	dockedItems			: [{
		xtype	: 'toolbar',
		dock	: 'top',
		items	: []
	}],
	statics				:
	{
		C_STR_PRINT_SERVER	: "7B0474F4-F829-4DEC-9EA4-6C4E8B58293B"
	},
	requires			:
	[
			"AmpleHarvest.views.article.cArticleView",
			"AmpleHarvest.objects.content.cContent",
			"AmpleHarvest.objects.harvestMetadata.cMetaData"
	],
	border				: 0,
	layout				: "border",
	
	listeners		:
	{
		objectResponse	: function(object)
		{
			this.add(object);
			this.m_obj_TranslateButton.show();
		},
		
		buttonResponse	: function(object)
		{
			var toolbar = this.down("toolbar");
			
			if(toolbar.items.length >= 1) {
				toolbar.add('-');
			}
			
			toolbar.add(this.m_obj_ParentButton);
		},
		
	},

	initComponent		: function()
	{
		this.tools =
		[
				{
					type	: "maximize",
					tooltip	: "Collapse all panels",
					handler	: this.maximize,
					scope	: this
				},
				{
					type	: "restore",
					tooltip	: "Expand all panels",
					handler	: this.restore,
					scope	: this
				},
				{
					type	: "print",
					tooltip	: "Print",
					handler	: this.print,
					scope	: this
				}

		];
		
		this.m_obj_ArticleWin = Ext.create(
				"AmpleHarvest.objects.content.cContent",
				{
					ahCaller			: this,
					m_str_id			: this.m_str_id,
					flex				: 1,
					region 				: "center",
					str_data_source		: obj_config.C_STR_EXTERNAL_PATH+'/rest/data/data.php',
					verifyData			: function (obj_response)
					{
						if(!obj_response.content) return false;
						if(!obj_response.title) return false;
						if(!obj_response.classification) return false;
						return true;
					},
					transformData 		: function(object)
					{
						var obj_return = { 
								content 		: object.content,
								title			: object.title,
								language		: object.language,
								classification	: object.classification
							};
						return obj_return;
					},
					writeContent		: function(obj_data)
					{
						this.translateContent = obj_data.content;
						this.classification = obj_data.classification;
						this.language = obj_data.language;
						this.update(obj_data.content);
						this.ahCaller.setTitle(obj_data.title);
						this.ahCaller.fireEvent('objectResponse', this);
						this.fireEvent(
								AmpleHarvest.layout.cLayout.C_STR_EVENT_CLASSIFICATION_CHANGE,
								obj_data.classification
						);
					}
				}
		);
		
		this.m_obj_MetaDataWin = Ext.create(
				"AmpleHarvest.objects.harvestMetadata.cMetaData",
				{
					
					ahCaller			: this,
					m_str_id			: this.m_str_id,
					collapseDirection	: 'bottom',
					region				: "south"
				}
		);
		
		this.m_obj_ParentButton = Ext.create(
				"AmpleHarvest.objects.breadcrumbs.cGoToParent",
				{
					ahCaller			: this,
					m_str_id			: this.m_str_id
				}
		);
		this.m_obj_TranslateButton = Ext.create("AmpleHarvest.views.article.cTranslationButton",
				{
					ahCaller : this
				});
		this.m_obj_TranslateButton.hide();
		
		// TODO: handle the paging in a multi page document more gracefully
//		this.m_obj_NextButton = Ext.create("Ext.button.Button",
//		{
//			width	: 25,
//			text	: ">",
//			hidden	: true,
//			handler	: function()
//			{
//				m_obj_AmpleHarvest_ViewPort
//						.fireEvent(
//								AmpleHarvest.views.article.eventHandler.cWindowEvents.C_STR_EVENT_ARTICLE_PAGE_CHANGE,
//								this.m_str_PageID, this.m_str_ServerID
//						);
//			},
//			region	: "east"
//		}
//		);
//
//		this.m_obj_PreviousButton = Ext.create("Ext.button.Button",
//		{
//			width	: 25,
//			text	: "<",
//			hidden	: true,
//			handler	: function()
//			{
//				m_obj_AmpleHarvest_ViewPort
//						.fireEvent(
//								AmpleHarvest.views.article.eventHandler.cWindowEvents.C_STR_EVENT_ARTICLE_PAGE_CHANGE,
//								this.m_str_PageID, this.m_str_ServerID
//						);
//			},
//			region	: "west"
//		}
//		);

		this.items =
		[
//				this.m_obj_ArticleWin
				//, this.m_obj_MetaDataWin
				//TODO : RELATED TO above
//				this.m_obj_NextButton, this.m_obj_PreviousButton
		];
		
		
		this.callParent();
		this.down("toolbar").add(this.m_obj_TranslateButton);
		
	
		
			// TODO : Fix how this is called. viewport should not be required to exist at this time
//		this.on("render", this.activate_Events, this);

	},
			// TODO : related to above
//	activate_Events		: function()
//	{
//		m_obj_AmpleHarvest_ViewPort
//				.on(
//						AmpleHarvest.views.article.eventHandler.cWindowEvents.C_STR_EVENT_ARTICLE_PAGE_NEXT_ACTIVATE,
//						this.activateNext, this
//				);
//
//		m_obj_AmpleHarvest_ViewPort
//				.on(
//						AmpleHarvest.views.article.eventHandler.cWindowEvents.C_STR_EVENT_ARTICLE_PAGE_PREVIOUS_ACTIVATE,
//						this.activatePrevious, this
//				);
//	},


	
//	add_JsonObject		: function(JsonObject, id)
//	{
//		this.m_str_id = id;
//		this.setTitle(JsonObject.title);
//		this.m_obj_ArticleWin.add_JsonObject(JsonObject.content);
//		this.m_obj_MetaDataWin.add_JsonObject(JsonObject);
//	},

	push_JsonNotFound	: function(title, content)
	{
		this.setTitle(title);
		this.m_obj_ArticleWin.add_JsonObject(content);
	},

	
	//TODO : get pushed HL working
	push_highlight		: function(hl_object, str_Class, str_Attrib)
	{
		this.m_obj_ArticleWin.highlight(hl_object, str_Class, str_Attrib);
	},

	collapse			: function()
	{
		this.m_obj_MetaDataWin.collapse();
	},

	expand				: function()
	{
		this.m_obj_MetaDataWin.expand();
	},

	maximize			: function()
	{
		this.ownerCt.collapseAll();
		//this.up('ampleharvest-views_article-carticle').collapseAll();
	},

	restore				: function()
	{
		this.ownerCt.expandAll();
		//this.up('ampleharvest-views_article-carticle').expandAll();
	},

	print				: function()
	{
		m_obj_AmpleHarvest_ViewPort
				.fireEvent(
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_REDIRECT_NEW_WIN,
						this.self.C_STR_PRINT_SERVER, this.m_str_id
				);
	},
	activateNext		: function(str_ServerID, str_ID)
	{
		this.m_obj_NextButton.m_str_PageID = str_ID;
		this.m_obj_NextButton.m_str_ServerID = str_ServerID;
		this.m_obj_NextButton.show();
	},

	activatePrevious	: function(str_ServerID, str_ID)
	{
		this.m_obj_PreviousButton.m_str_PageID = str_ID;
		this.m_obj_PreviousButton.m_str_ServerID = str_ServerID;
		this.m_obj_PreviousButton.show();
	}
}
);
